$(function(){
		
	})

function ajax(path,param){
	$.ajax
		({
	  url:path,
	  cache: false,
	  async: true,
	  type: "POST",
	  data:param,
	  success: function(html){
	  	if(html=="succ"){
	  		location.reload();
	  	}
	  	else{
	  		$.MsgBox.Alert('消息',"出现错误");
	  	}
	  }
	}); 
}
	
Date.prototype.Format = function (fmt) { 
var o = {
    "M+": this.getMonth() + 1, // 月份
    "d+": this.getDate(), // 日
    "h+": this.getHours(), // 小时
    "m+": this.getMinutes(), // 分
    "s+": this.getSeconds(), // 秒
    "q+": Math.floor((this.getMonth() + 3) / 3), // 季度
    "S": this.getMilliseconds() // 毫秒
};
if (/(y+)/.test(fmt)) {
    fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
}
for (var k in o)
    if (new RegExp("(" + k + ")").test(fmt)) 
        fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
	return fmt;
}

function getDate(days)
{	   	
	var _date=new Date();
	_date.setDate(_date.getDate()+days)
	return _date.Format("yyyy-MM-dd");
}

function toSort(sortMode,sortName)
{	   	
	var sortUrl=winUrl(location.href,sortMode,sortName);
	window.location.href=sortUrl;
}

function toPage(pageIndex,pageSize)
{	   	
	var pageUrl=winUrl(window.location.href,"pageIndex",pageIndex);
	window.location.href=winUrl(pageUrl,"pageSize",pageSize);
}

// 删除左右两端的空格
function toTrim(str){   
	return str.replace(/(^\s*)|(\s*$)/g, ""); 
} 


// 替换url的参数
function replaceParam(param,value,url){
	if(!url){
		url = window.location.href;
	}
	var pathIndex = url.indexOf(param);
	// 如果url中没有次参数，添加
	if(pathIndex<0){
		url = url + "&" + param + "=" + value;
	}else{
		var urlBef = url.substring(0,pathIndex);
		var aft = url.substring(pathIndex,url.length);
		var urlAft;
		if(aft.indexOf("&")>0){
			 urlAft = aft.substring(aft.indexOf("&"));
		}else{
			urlAft = "";
		}
		url = urlBef + param + "=" + value + urlAft;
	}
	return url
}

function winUrl(urlStr,qs,parm)
{	
	var url=urlStr;
	if(urlStr.indexOf("?")<0)
	{
		url= urlStr+"?"+qs+"="+parm;		
	}
	else if(urlStr.indexOf(qs+"=")<0){
		url= urlStr+"&"+qs+"="+parm;
	}	
	else{
		var s = urlStr.replace("?","?&").split("&");
		var re = "";
		for(i=1;i<s.length;i++){
		    if(s[i].indexOf(qs+"=")==0){
		        url= urlStr.replace(s[i],qs+"="+parm);
		    }
		}	
	}
	return url;
}

// 弹出框
(function () {
  $.MsgBox = {
    Alert: function (title, msg) {
      GenerateHtml("alert", title, msg);
      btnOk(); // alert只是弹出消息，因此没必要用到回调函数callback
      btnNo();
    },
    Confirm: function (title, msg, callback) {
      GenerateHtml("confirm", title, msg);
      btnOk(callback);
      btnNo();
    }
  }
 
  // 生成Html
  var GenerateHtml = function (type, title, msg) {
    var _html = "";
    _html += '<div id="mb_box"></div><div id="mb_con"><span id="mb_tit">' + title + '</span>';
    _html += '<a id="mb_ico">x</a><div id="mb_msg">' + msg + '</div><div id="mb_btnbox">';
    if (type == "alert") {
      _html += '<input id="mb_btn_ok" type="button" value="Yes" />';
    }
    if (type == "confirm") {
      _html += '<input id="mb_btn_ok" type="button" value="Yes" />';
      _html += '<input id="mb_btn_no" type="button" value="No" />';
    }
    _html += '</div></div>';
    $("body").append(_html); GenerateCss();
  }
 
  // 生成Css
  var GenerateCss = function () {
 
    $("#mb_box").css({ width: '100%', height: '100%', zIndex: '99999', position: 'fixed',
      filter: 'Alpha(opacity=0)', backgroundColor: 'black', top: '0', left: '0', opacity: '0.0'
    });
 
    $("#mb_con").css({ zIndex: '999999', width: '400px', position: 'fixed',
      backgroundColor: 'White',border:'1px solid #1c3e57'
    });
 
    $("#mb_tit").css({ display: 'block', fontSize: '12px', color: '#fff', padding: '8px 8px',
      backgroundColor: '#1c3e57'
    });
 
    $("#mb_msg").css({ padding: '20px', lineHeight: '20px',
      borderBottom: '1px dashed #DDD', fontSize: '13px'
    });
 
    $("#mb_ico").css({ display: 'block', position: 'absolute', right: '5px', top: '5px',
      border: '1px solid #fff', width: '18px', height: '18px', textAlign: 'center',
      lineHeight: '16px', cursor: 'pointer',color:'white'
    });
 
    $("#mb_btnbox").css({ margin: '15px 0 10px 0', textAlign: 'center' });
    $("#mb_btn_ok,#mb_btn_no").css({ width: '85px', height: '25px', color: 'white', border: 'none',cursor: 'pointer', });
    $("#mb_btn_ok").css({ backgroundColor: '#1c3e57' });
    $("#mb_btn_no").css({ backgroundColor: 'gray', marginLeft: '20px' });
 
    var _widht = document.documentElement.clientWidth; // 屏幕宽
    var _height = document.documentElement.clientHeight; // 屏幕高
 
    var boxWidth = $("#mb_con").width();
    var boxHeight = $("#mb_con").height();
 
    // 让提示框居中
    $("#mb_con").css({ top: (_height ) / 2- boxHeight-50 + "px", left: (_widht - boxWidth) / 2-150 + "px" });
  }
 
  // 确定按钮事件
  var btnOk = function (callback) {
    $("#mb_btn_ok").click(function () {
      $("#mb_box,#mb_con").remove();
      if (typeof (callback) == 'function') {
        callback();
      }
    });
  }
 
  // 取消按钮事件
  var btnNo = function () {
    $("#mb_btn_no,#mb_ico").click(function () {
      $("#mb_box,#mb_con").remove();
    });
  }
})();















